package com.xinqi.modules.sys.document.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.document.client.DocumentManagerClient;
import com.xinqi.modules.sys.document.dto.req.DocumentManagerCreateDTO;
import com.xinqi.modules.sys.document.dto.req.DocumentManagerQueryDTO;
import com.xinqi.modules.sys.document.dto.req.DocumentManagerUpdateDTO;
import com.xinqi.modules.sys.document.dto.rsp.DocumentManagerResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 文档管理表降级处理
 *
 * @author: gzy
 * @date: 2023/05/28
 */
@Slf4j
@Component
public class DocumentManagerFallbackFactory implements FallbackFactory<DocumentManagerClient> {

    @Override
    public DocumentManagerClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new DocumentManagerClient() {
            @Override
            public R<PageInfo<DocumentManagerResultDTO>> page(DocumentManagerQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<DocumentManagerResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(DocumentManagerCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, DocumentManagerUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
